<template>
    <div>
        <el-input v-model="queryData.clientName" placeholder="客户名称" size="small"></el-input>
        <el-input v-model="queryData.operatorName" placeholder="操作员工" size="small"></el-input>
<!--        <el-divider direction="vertical"></el-divider>-->&nbsp;&nbsp;
        <el-button type="primary" @click="queryDataHandle(1, 10)" size="small">查询</el-button>
<!--        <el-divider direction="vertical"></el-divider>-->
        <el-button type="primary" @click="resetQuery" size="small">重置</el-button>
        <el-divider></el-divider>
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span style="font-size: 12px">共{{ dataSource.length }}个客户</span>
                <div style="float: right; padding: 3px 0">
<!--                    <el-button plain size="mini">导入客户</el-button>
                    <el-divider direction="vertical"></el-divider>-->
                    <el-button type="primary" size="mini" @click="exportHandle">导出excel</el-button>
                </div>
            </div>
            <div>
                <el-table :data="dataSource" :header-cell-style="{background:'#F3F4F7',color:'#555'}" style="width: 100%">
                    <el-table-column prop="clientName" label="客户昵称"></el-table-column>
                    <el-table-column prop="createTime" label="操作时间" :formatter="formatter"></el-table-column>
                    <el-table-column prop="empName" label="操作人"></el-table-column>
                    <el-table-column prop="description" label="原因" ></el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button @click="detailHandle(scope.row)" type="text" size="small">客户详情</el-button>
                            <el-button @click="deleteHandle(scope.row)" type="text" size="small">移除</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <div class="interspaceH"></div>

                <el-pagination @size-change="queryDataHandle(pagePagination.currentPage,$event)"
                               @current-change="queryDataHandle($event,pagePagination.pageSize)"
                               :current-page="pagePagination.currentPage"
                               :page-sizes="pagePagination.pageSizes" :page-size="pagePagination.pageSize"
                               layout="total, sizes, prev, pager, next"
                               :total="pagePagination.total">
                </el-pagination>
            </div>
        </el-card>

        <ClientDetail ref="clientDetail"/>
    </div>
</template>

<script>
import ClientDetail from '@/views/customer/client/client_detail'
const queryData = {
    clientName:'',//客户名称
    operatorName: '',//操作员工
}

//多选框 - 开始

//多选框 - 结束

export default {
    name: "blacklist",
    components: {
        ClientDetail
    },
    data() {
        return {
            tablePage: 0,
            detailVisible: false,
            dictionary: {
            },
            fieldType: {
                operationTime: "datetime"
            },
            queryData: {...queryData},
            dataSource: [],
            pagePagination: {
                currentPage: 1,
                pageSizes: [10, 15, 20, 25],
                pageSize: 10,
                total: 0
            }
        }
    },
    mounted() {
        this.queryDataHandle()
    },
    methods: {
        queryDataHandle(page = 1, row = 10) {
            let that = this;
            let queryData = {...that.queryData}

            if (queryData.joinTime != null && queryData.joinTime != "") {
                queryData['startJoinTime'] = queryData.joinTime[0]
                queryData['endJoinTime'] = queryData.joinTime[1]
                delete queryData.joinTime
            }

            let payload = {
                ...queryData,
                clientType: '-1',
                pageNum: page,
                pageSize: row
            }
            that.$request("/clientHistory/getBackList", payload, "POST").then((data) => {
                that.dataSource = data.data.data
                that.pagePagination['total'] = data.data.total
                that.pagePagination['pageSize'] = data.data.pageSize
            })
        },
        resetQuery() {
            this.queryData = queryData
            this.$message({
                message: '重置成功',
                type: 'success'
            });
        },
        formatter(row, column) {
            let field = column.property;
            let value = row[field];
            return this.$utils.formatterForLable(field, value, this.fieldType, this['dictionary'][field]);
        },
        deleteHandle(data) {
            this.$confirm('是否确认移除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                /*let payload = {
                    clientIds: [row.clientId]
                }
                this.$request("/api/customers/deleteCustomersByIds/1_0", payload, "POST").then((data) => {
                    this.$message({
                        type: 'success',
                        message: '移除成功!'
                    });
                    this.queryDataHandle()
                })*/
                // let payload = {
                //     clientId: data.clientId,
                //     empId: data.empId,
                //     clientType: "1",
                //     clientIsFriend: "false",
                //     clientHistoryRemark: this.$store.getters.getUserInfo.userNickname + "将客户移除至黑名单"
                // }
                this.$request("/client/deleteBack/"+data.clientId, "POST").then((data) => {
                    this.$message.success("将客户移除至黑名单成功！")
                    this.queryDataHandle();
                })
            })
        },
        detailHandle(row) {
            this.$refs.clientDetail.open(true, row)
        },
        exportHandle() {
            this.$requestFile("/api/customers/exportCustomers/1_0", {clientType: '-1'}, "黑名单客户列表.xlsx")
        },
    }
}
</script>

<style scoped>
.el-input {
    width: 200px;
}

.box-card .el-select {
    width: 200px;
}
.el-form-item__content .el-input {
    width: 100%;
}
</style>
